package com.zhbr.mvp.presenter;

import com.zhbr.entity.Account;
import com.zhbr.common.rx.BaseSubscriber;
import com.zhbr.mvp.contract.LoginContract;
import com.zhbr.mvp.base.presenter.BasePresenter;
import com.zhbr.mvp.model.LoginModel;

import java.util.HashMap;
import java.util.Map;

public class LoginPresenter extends BasePresenter<LoginContract.View,LoginContract.Model> implements LoginContract.Presenter{


    @Override
    public void login(String username, String password) {

//        showLoading();
        Map<String,String> params = new HashMap<>();
        params.put("phone",username);
        params.put("password",password);

        mModel.login(params, new BaseSubscriber<Account>() {
            @Override
            public void onSuccess(Account data) {
//                dismissLoading();
                if (isViewAttach()){
                    getView().onLoginSuccess(data);
                }
            }

            @Override
            public void onFailed(Throwable ex, String code, String msg) {
                getView().onLoginFail(ex, code, msg);
            }

            @Override
            public void onError() {
                getView().onNetError();
            }
        });


    }

    @Override
    protected LoginContract.Model createModule() {
        return new LoginModel();
    }
}
